#!/bin/bash
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#

export ORACLE_HOME=/opt/oracle/app/product
LOCK=/var/lock/subsys/oracle

export PATH=${PATH}:$ORACLE_HOME/bin

case $1 in
'start')
  if [[ -f $LOCK ]]; then
    echo Oracle was already started at $(date -r $LOCK)
  else
    su - oracle -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
    touch $LOCK
  fi
  ;;
'stop')
  if [[ -f $LOCK ]]; then
    su - oracle -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
    rm -f $LOCK
  else
    echo Oracle is not started
  fi
  ;;
'status')
  if [[ -f $LOCK ]]; then
    echo Oracle started at $(date -r $LOCK)
  else
    echo Oracle is not started
  fi
  ;;
*)
  echo "usage: $0 {start|stop|status}"
  exit
  ;;
esac
